package com.liu.controller;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.liu.model.User;
import com.liu.model.VisitDao;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
@WebServlet("/visit")
public class VisitServlet extends HttpServlet{
    private ObjectMapper objectMapper = new ObjectMapper();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("text/html;charset=UTF-8");
        System.out.println(11);
        String param = req.getParameter("blogId");
        if (param == null) return;
        else {
            HttpSession session = req.getSession(false);
            User user = (User)session.getAttribute("user");
            int userId = user.getUserId();
            VisitDao visitDao = new VisitDao();
            int blodId = Integer.parseInt(param);
            visitDao.insertById(blodId, userId);
            resp.getWriter().write("访问成功！");
        }
    }
}
